package com.yunmang.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.yunmang.R;
import com.yunmang.entity.ParameterEntity.ConfirmBean;
import com.yunmang.utils.ViewHolderUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/9.
 */
public class ConfirmAdapter extends BaseAdapter{
    private Context context;
    private List<ConfirmBean.ModelBean.ItemsBean> dataList;

    public Map<Integer,Boolean> isselect;
    public List<String> hasSelected=new ArrayList<String>();

    private boolean isClearAll=false;

    public void setSelectAll(boolean selectAll) {
        isSelectAll = selectAll;
    }

    private boolean isSelectAll=false;
    public ConfirmAdapter(Context context, List<ConfirmBean.ModelBean.ItemsBean> dataList){
        this.context=context;
        this.dataList=dataList;
        init();
    }
    public void init(){
        isselect=new HashMap<Integer, Boolean>();
        for(int i=0;i<dataList.size();i++){
            isselect.put(i, false);
        }
    }
    public void initseleted(){
        isselect=new HashMap<Integer, Boolean>();
        for(int i=0;i<dataList.size();i++){
            isselect.put(i, true);
        }
    }
    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ConfirmBean.ModelBean.ItemsBean itemsBean = dataList.get(i);
        if(convertView==null)
            convertView=View.inflate(context, R.layout.item_transport, null);
//        TextView tv_id= ViewHolderUtils.get(convertView,R.id.tv_id);
        TextView tv_orderID= ViewHolderUtils.get(convertView,R.id.tv_orderID);
        TextView tv_end= ViewHolderUtils.get(convertView,R.id.tv_end);
        TextView tv_num= ViewHolderUtils.get(convertView,R.id.tv_num);
        TextView tv_freight= ViewHolderUtils.get(convertView,R.id.tv_freight);
        TextView tv_goods_name= ViewHolderUtils.get(convertView,R.id.tv_goods_name);
        CheckBox cb= ViewHolderUtils.get(convertView,R.id.cb_choose);

        TextView tvscan_num= ViewHolderUtils.get(convertView,R.id.tv_sacn_num);
        TextView tv_scan_status= ViewHolderUtils.get(convertView,R.id.tv_scan_status);
//        tv_id.setText((i+1)+"");
        tv_orderID.setText(itemsBean.getHdbh());
//        tv_start.setText(itemsBean.getStartDepartName());
        tv_freight.setText(itemsBean.getTransportCost()+"");
        tv_goods_name.setText(itemsBean.getGoodsName());
        tv_num.setText(itemsBean.getNumbers()+"");
        tv_end.setText(itemsBean.getStartDepartName());
        tvscan_num.setText(itemsBean.getSaomiaonum());
        if(itemsBean.getSaomiaonum().trim().equals(itemsBean.getNumbers()+"")){
            tvscan_num.setTextColor(context.getResources().getColor(R.color.green0));
            tv_scan_status.setText("已扫完");
            tv_scan_status.setTextColor(context.getResources().getColor(R.color.green0));
            tv_scan_status.setBackgroundResource(R.drawable.bg_scan_finish);
        }else{
            tvscan_num.setTextColor(context.getResources().getColor(R.color.red));
            tv_scan_status.setText("未扫完");
            tv_scan_status.setTextColor(context.getResources().getColor(R.color.red));
            tv_scan_status.setBackgroundResource(R.drawable.bg_del);
        }
        boolean is=isselect.get(i);
        if(is){
            cb.setChecked(true);
        }else{
            cb.setChecked(false);
        }
        if(isClearAll)
            cb.setChecked(false);
        if(isSelectAll)
            cb.setChecked(true);
        return convertView;
    }
    public void isClearAllCheckBox(boolean isClear){
        isClearAll=isClear;
    }
    public void refreshData(List<ConfirmBean.ModelBean.ItemsBean> dataList){
        this.dataList=dataList;
        init();
        notifyDataSetChanged();
    }
    public void refreshSeletedData(List<ConfirmBean.ModelBean.ItemsBean> dataList){
        this.dataList=dataList;
        initseleted();
        notifyDataSetChanged();
    }
}
